
// 画线
function ctxDrawLine(ctx, x1, y1, x2, y2, lineWidth, dash, color){ 
  ctx.fillStyle   = (color instanceof Array)?`rgb(${color[0]}, ${color[1]}, ${color[2]})`:color;
  ctx.strokeStyle = (color instanceof Array)?`rgb(${color[0]}, ${color[1]}, ${color[2]})`:color;
  ctx.lineWidth   = lineWidth;
  ctx.setLineDash(dash);
  ctx.beginPath();
  ctx.moveTo(x1, y1);
  ctx.lineTo(x2, y2);
  ctx.stroke();
}
// 画圆
function ctxDrawCircle(ctx, cx, cy, r=5, fill, start, end, color, lineWidth, dash){
  ctx.strokeStyle = (color instanceof Array)?`rgb(${color[0]}, ${color[1]}, ${color[2]})`:color;
  ctx.fillStyle   = (color instanceof Array)?`rgb(${color[0]}, ${color[1]}, ${color[2]})`:color;
  ctx.lineWidth   = lineWidth;
  ctx.setLineDash(dash);
  ctx.beginPath();
  ctx.arc(cx, cy, r, start, end, false);
  if(fill){
    ctx.fill();
  }
  else{
    ctx.stroke();
  }
}
// 画矩形
function ctxDrawRectangle(ctx, x, y, w, h, fill, color, lineWidth, dash){
  ctx.strokeStyle = (color instanceof Array)?`rgb(${color[0]}, ${color[1]}, ${color[2]})`:color;
  ctx.fillStyle   = (color instanceof Array)?`rgb(${color[0]}, ${color[1]}, ${color[2]})`:color;
  ctx.lineWidth   = lineWidth;
  ctx.setLineDash(dash);
  ctx.beginPath();
  ctx.rect(x, y, w, h);
  if(fill){
    ctx.fill();
  }
  else{
    ctx.stroke();
  }
}
// 画三角形
function ctxDrawTrangle(ctx, p1, p2, p3, fill, color, lineWidth, dash){
  ctx.strokeStyle = (color instanceof Array)?`rgb(${color[0]}, ${color[1]}, ${color[2]})`:color;
  ctx.fillStyle   = (color instanceof Array)?`rgb(${color[0]}, ${color[1]}, ${color[2]})`:color;
  ctx.lineWidth   = lineWidth;
  ctx.setLineDash(dash);
  ctx.beginPath();
  ctx.moveTo(p1[0], p1[1]);
  ctx.lineTo(p2[0], p2[1]);
  ctx.lineTo(p3[0], p3[1]);
  ctx.closePath();
  if(fill){
    ctx.fill();
  }
  else{
    ctx.stroke();
  }
}
// 写字符串
function ctxDrawString(ctx, str, x, y, color, font, size, fill, lineWidth, dash){
  ctx.strokeStyle = (color instanceof Array)?`rgb(${color[0]}, ${color[1]}, ${color[2]})`:color;
  ctx.fillStyle   = (color instanceof Array)?`rgb(${color[0]}, ${color[1]}, ${color[2]})`:color;
  ctx.lineWidth   = lineWidth;
  ctx.setLineDash(dash);
  ctx.font        = `${size}px ${font}`;
  if(fill){
    ctx.fillText(str, x, y);
  }else{
    ctx.strokeText(str, x, y);
  }
}

export {
  ctxDrawCircle, 
  ctxDrawRectangle, 
  ctxDrawString,
  ctxDrawTrangle,
  ctxDrawLine,
}